home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / pbm3 / part3 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  48.3 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: jef@helios.ee.lbl.gov (Jef Poskanzer)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i043: portable bitmap routines (3 of 5)
  5. Message-ID: <8811010237.AA02698@helios.ee.lbl.gov>
  6. Date: 9 Nov 88 02:38:22 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: jef@helios.ee.lbl.gov (Jef Poskanzer)
  9. Lines: 1937
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 43
  13. Submitted-by: "Jef Poskanzer" <jef@helios.ee.lbl.gov>
  14. Archive-name: pbm3/Part3
  15.  
  16. [Yuck.  I'd prefer real subject lines.  ++bsa]
  17.  
  18. #! /bin/sh
  19. # This is a shell archive, meaning:
  20. # 1. Remove everything above the #! /bin/sh line.
  21. # 2. Save the resulting text in a file.
  22. # 3. Execute the file with /bin/sh (not csh) to create the files:
  23. #    pbmfliptb.c
  24. #    pbmfliptb.1
  25. #    pbminvert.c
  26. #    pbminvert.1
  27. #    pbmcrop.c
  28. #    pbmcrop.1
  29. #    pbmtrnspos.c
  30. #    pbmtrnspos.1
  31. #    pbmcut.c
  32. #    pbmcut.1
  33. #    pbmpaste.c
  34. #    pbmpaste.1
  35. #    xxxtopbm.c
  36. #    xxxtopbm.1
  37. #    pbmenlarge.c
  38. #    pbmenlarge.1
  39. #    pbmmake.c
  40. #    pbmmake.1
  41. #    pbmtolj.c
  42. #    pbmtolj.1
  43. #    pbmtomacp.c
  44. # This archive created: Mon Oct 31 18:33:35 1988
  45. # By:    Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
  46. export PATH; PATH=/bin:$PATH
  47. echo shar: extracting "'pbmfliptb.c'" '(1305 characters)'
  48. if test -f 'pbmfliptb.c'
  49. then
  50.     echo shar: will not over-write existing file "'pbmfliptb.c'"
  51. else
  52. sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.c'
  53. X/* pbmfliptb.c - read a portable bitmap and flip it top for bottom
  54. X**
  55. X** Copyright (C) 1988 by Jef Poskanzer.
  56. X**
  57. X** Permission to use, copy, modify, and distribute this software and its
  58. X** documentation for any purpose and without fee is hereby granted, provided
  59. X** that the above copyright notice appear in all copies and that both that
  60. X** copyright notice and this permission notice appear in supporting
  61. X** documentation.  This software is provided "as is" without express or
  62. X** implied warranty.
  63. X*/
  64. X
  65. X#include <stdio.h>
  66. X#include "pbm.h"
  67. X
  68. Xmain( argc, argv )
  69. Xint argc;
  70. Xchar *argv[];
  71. X    {
  72. X    FILE *ifd;
  73. X    bit **bits, b;
  74. X    int rows, cols, row, col;
  75. X
  76. X    if ( argc > 2 )
  77. X    {
  78. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  79. X    exit( 1 );
  80. X    }
  81. X
  82. X    if ( argc == 2 )
  83. X    {
  84. X        ifd = fopen( argv[1], "r" );
  85. X        if ( ifd == NULL )
  86. X        {
  87. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  88. X        exit( 1 );
  89. X        }
  90. X    }
  91. X    else
  92. X    ifd = stdin;
  93. X
  94. X    bits = pbm_readpbm( ifd, &cols, &rows );
  95. X
  96. X    if ( ifd != stdin )
  97. X    fclose( ifd );
  98. X
  99. X    for ( row = 0; row < rows / 2; row++ )
  100. X        for ( col = 0; col < cols; col++ )
  101. X        {
  102. X        b = bits[row][col];
  103. X        bits[row][col] = bits[rows-row-1][col];
  104. X        bits[rows-row-1][col] = b;
  105. X        }
  106. X
  107. X    pbm_writepbm( stdout, bits, cols, rows );
  108. X
  109. X    exit( 0 );
  110. X    }
  111. SHAR_EOF
  112. if test 1305 -ne "`wc -c < 'pbmfliptb.c'`"
  113. then
  114.     echo shar: error transmitting "'pbmfliptb.c'" '(should have been 1305 characters)'
  115. fi
  116. fi # end of overwriting check
  117. echo shar: extracting "'pbmfliptb.1'" '(709 characters)'
  118. if test -f 'pbmfliptb.1'
  119. then
  120.     echo shar: will not over-write existing file "'pbmfliptb.1'"
  121. else
  122. sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.1'
  123. X.TH pbmfliptb 1 "31 August 1988"
  124. X.SH NAME
  125. Xpbmfliptb - flip a portable bitmap top for bottom
  126. X.SH SYNOPSIS
  127. Xpbmfliptb [pbmfile]
  128. X.SH DESCRIPTION
  129. XReads a portable bitmap as input.
  130. XFlips it top for bottom and produces a portable bitmap as output.
  131. X.SH "SEE ALSO"
  132. Xpbmfliplr(1), pbmtrnspos(1), pbm(5)
  133. X.SH AUTHOR
  134. XCopyright (C) 1988 by Jef Poskanzer.
  135. X
  136. XPermission to use, copy, modify, and distribute this software and its
  137. Xdocumentation for any purpose and without fee is hereby granted, provided
  138. Xthat the above copyright notice appear in all copies and that both that
  139. Xcopyright notice and this permission notice appear in supporting
  140. Xdocumentation.  This software is provided "as is" without express or
  141. Ximplied warranty.
  142. SHAR_EOF
  143. if test 709 -ne "`wc -c < 'pbmfliptb.1'`"
  144. then
  145.     echo shar: error transmitting "'pbmfliptb.1'" '(should have been 709 characters)'
  146. fi
  147. fi # end of overwriting check
  148. echo shar: extracting "'pbminvert.c'" '(1224 characters)'
  149. if test -f 'pbminvert.c'
  150. then
  151.     echo shar: will not over-write existing file "'pbminvert.c'"
  152. else
  153. sed 's/^X//' << \SHAR_EOF > 'pbminvert.c'
  154. X/* pbminvert.c - read a portable bitmap and invert it
  155. X**
  156. X** Copyright (C) 1988 by Jef Poskanzer.
  157. X**
  158. X** Permission to use, copy, modify, and distribute this software and its
  159. X** documentation for any purpose and without fee is hereby granted, provided
  160. X** that the above copyright notice appear in all copies and that both that
  161. X** copyright notice and this permission notice appear in supporting
  162. X** documentation.  This software is provided "as is" without express or
  163. X** implied warranty.
  164. X*/
  165. X
  166. X#include <stdio.h>
  167. X#include "pbm.h"
  168. X
  169. Xmain( argc, argv )
  170. Xint argc;
  171. Xchar *argv[];
  172. X    {
  173. X    FILE *ifd;
  174. X    bit **bits;
  175. X    int rows, cols, row, col;
  176. X
  177. X    if ( argc > 2 )
  178. X    {
  179. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  180. X    exit( 1 );
  181. X    }
  182. X
  183. X    if ( argc == 2 )
  184. X    {
  185. X        ifd = fopen( argv[1], "r" );
  186. X        if ( ifd == NULL )
  187. X        {
  188. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  189. X        exit( 1 );
  190. X        }
  191. X    }
  192. X    else
  193. X    ifd = stdin;
  194. X
  195. X    bits = pbm_readpbm( ifd, &cols, &rows );
  196. X
  197. X    if ( ifd != stdin )
  198. X    fclose( ifd );
  199. X
  200. X    for ( row = 0; row < rows; row++ )
  201. X        for ( col = 0; col < cols; col++ )
  202. X        bits[row][col] = ( bits[row][col] == 0 ? 1 : 0 );
  203. X
  204. X    pbm_writepbm( stdout, bits, cols, rows );
  205. X
  206. X    exit( 0 );
  207. X    }
  208. SHAR_EOF
  209. if test 1224 -ne "`wc -c < 'pbminvert.c'`"
  210. then
  211.     echo shar: error transmitting "'pbminvert.c'" '(should have been 1224 characters)'
  212. fi
  213. fi # end of overwriting check
  214. echo shar: extracting "'pbminvert.1'" '(672 characters)'
  215. if test -f 'pbminvert.1'
  216. then
  217.     echo shar: will not over-write existing file "'pbminvert.1'"
  218. else
  219. sed 's/^X//' << \SHAR_EOF > 'pbminvert.1'
  220. X.TH pbminvert 1 "13 February 1988"
  221. X.SH NAME
  222. Xpbminvert - invert a portable bitmap
  223. X.SH SYNOPSIS
  224. Xpbminvert [pbmfile]
  225. X.SH DESCRIPTION
  226. XReads a portable bitmap as input.
  227. XInverts it black for white and produces a portable bitmap as output.
  228. X.SH "SEE ALSO"
  229. Xpbm(5)
  230. X.SH AUTHOR
  231. XCopyright (C) 1988 by Jef Poskanzer.
  232. X
  233. XPermission to use, copy, modify, and distribute this software and its
  234. Xdocumentation for any purpose and without fee is hereby granted, provided
  235. Xthat the above copyright notice appear in all copies and that both that
  236. Xcopyright notice and this permission notice appear in supporting
  237. Xdocumentation.  This software is provided "as is" without express or
  238. Ximplied warranty.
  239. SHAR_EOF
  240. if test 672 -ne "`wc -c < 'pbminvert.1'`"
  241. then
  242.     echo shar: error transmitting "'pbminvert.1'" '(should have been 672 characters)'
  243. fi
  244. fi # end of overwriting check
  245. echo shar: extracting "'pbmcrop.c'" '(4241 characters)'
  246. if test -f 'pbmcrop.c'
  247. then
  248.     echo shar: will not over-write existing file "'pbmcrop.c'"
  249. else
  250. sed 's/^X//' << \SHAR_EOF > 'pbmcrop.c'
  251. X/* pbmcrop.c - crop a portable bitmap
  252. X**
  253. X** Copyright (C) 1988 by Jef Poskanzer.
  254. X**
  255. X** Permission to use, copy, modify, and distribute this software and its
  256. X** documentation for any purpose and without fee is hereby granted, provided
  257. X** that the above copyright notice appear in all copies and that both that
  258. X** copyright notice and this permission notice appear in supporting
  259. X** documentation.  This software is provided "as is" without express or
  260. X** implied warranty.
  261. X*/
  262. X
  263. X#include <stdio.h>
  264. X#include "pbm.h"
  265. X
  266. Xmain( argc, argv )
  267. Xint argc;
  268. Xchar *argv[];
  269. X    {
  270. X    FILE *ifd;
  271. X    bit **bits, **newbits, background;
  272. X    int argn, backdefault, c;
  273. X    int rows, cols, row, col, newrows, newcols;
  274. X    int top, bottom, left, right;
  275. X    char *usage = "usage:  %s [-0]/[-w]/[-1]/[-b] [pbmfile]\n";
  276. X
  277. X    argn = 1;
  278. X    backdefault = 1;
  279. X
  280. X    /* Check for flags. */
  281. X    if ( argn < argc )
  282. X    {
  283. X    if ( argv[argn][0] == '-' )
  284. X        {
  285. X        if ( ( argv[argn][1] == '0' || argv[argn][1] == 'w' ||
  286. X           argv[argn][1] == 'W' ) && argv[argn][2] == '\0' )
  287. X        {
  288. X        backdefault = 0;
  289. X        background = 0;
  290. X        }
  291. X        else if ( ( argv[argn][1] == '1' || argv[argn][1] == 'b' ||
  292. X            argv[argn][1] == 'B' ) && argv[argn][2] == '\0' )
  293. X        {
  294. X        backdefault = 0;
  295. X        background = 1;
  296. X        }
  297. X        else
  298. X        {
  299. X        fprintf( stderr, usage, argv[0] );
  300. X        exit( 1 );
  301. X        }
  302. X        argn++;
  303. X        }
  304. X    }
  305. X
  306. X    if ( argn == argc )
  307. X    ifd = stdin;
  308. X    else
  309. X    {
  310. X        ifd = fopen( argv[argn], "r" );
  311. X        if ( ifd == NULL )
  312. X        {
  313. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  314. X        exit( 1 );
  315. X        }
  316. X    argn++;
  317. X    }
  318. X    bits = pbm_readpbm( ifd, &cols, &rows );
  319. X    if ( ifd != stdin )
  320. X    fclose( ifd );
  321. X
  322. X    if ( argn != argc )
  323. X    {
  324. X    fprintf( stderr, usage, argv[0] );
  325. X    exit( 1 );
  326. X    }
  327. X
  328. X    if ( backdefault )
  329. X    {
  330. X    /* Guess what the background is by looking for an edge of
  331. X    ** all one color.
  332. X    */
  333. X    c = 0;
  334. X    for ( col = 0; col < cols; col++ )
  335. X        c += bits[0][col];
  336. X    if ( c == 0 )
  337. X        background = 0;
  338. X    else if ( c == cols )
  339. X        background = 1;
  340. X    else
  341. X        {
  342. X        c = 0;
  343. X        for ( col = 0; col < cols; col++ )
  344. X        c += bits[rows - 1][col];
  345. X        if ( c == 0 )
  346. X        background = 0;
  347. X        else if ( c == cols )
  348. X        background = 1;
  349. X        else
  350. X        {
  351. X        c = 0;
  352. X        for ( row = 0; row < rows; row++ )
  353. X            c += bits[row][0];
  354. X        if ( c == 0 )
  355. X            background = 0;
  356. X        else if ( c == rows )
  357. X            background = 1;
  358. X        else
  359. X            {
  360. X            c = 0;
  361. X            for ( row = 0; row < rows; row++ )
  362. X            c += bits[row][cols - 1];
  363. X            if ( c == 0 )
  364. X            background = 0;
  365. X            else if ( c == rows )
  366. X            background = 1;
  367. X            else
  368. X            {
  369. X            fprintf( stderr, "(nothing to crop, continuing)\n" );
  370. X            background = 0;        /* arbitrary */
  371. X            }
  372. X            }
  373. X        }
  374. X        }
  375. X    }
  376. X
  377. X    /* Find first non-background line. */
  378. X    for ( top = 0; top < rows; top++ )
  379. X    for ( col = 0; col < cols; col++ )
  380. X        if ( bits[top][col] != background )
  381. X        goto gottop;
  382. Xgottop:
  383. X
  384. X    /* Find last non-background line. */
  385. X    for ( bottom = rows - 1; bottom >= top; bottom-- )
  386. X    for ( col = 0; col < cols; col++ )
  387. X        if ( bits[bottom][col] != background )
  388. X        goto gotbottom;
  389. Xgotbottom:
  390. X
  391. X    /* Find first non-background column. */
  392. X    for ( left = 0; left < cols; left++ )
  393. X    for ( row = top; row <= bottom; row++ )
  394. X        if ( bits[row][left] != background )
  395. X        goto gotleft;
  396. Xgotleft:
  397. X
  398. X    /* Find last non-background column. */
  399. X    for ( right = cols - 1; right > left; right-- )
  400. X    for ( row = top; row <= bottom; row++ )
  401. X        if ( bits[row][right] != background )
  402. X        goto gotright;
  403. Xgotright:
  404. X
  405. X    if ( top > 0 )
  406. X    fprintf( stderr, "(cropping %d %d-rows off the top)\n",
  407. X         top, background );
  408. X    if ( bottom < rows - 1 )
  409. X    fprintf( stderr, "(cropping %d %d-rows off the bottom)\n",
  410. X         rows - 1 - bottom, background );
  411. X    if ( left > 0 )
  412. X    fprintf( stderr, "(cropping %d %d-cols off the left)\n",
  413. X         left, background );
  414. X    if ( right < cols - 1 )
  415. X    fprintf( stderr, "(cropping %d %d-cols off the right)\n",
  416. X         cols - 1 - right, background );
  417. X
  418. X    /* Now copy into a new array. */
  419. X    newcols = right - left + 1;
  420. X    newrows = bottom - top + 1;
  421. X    newbits = pbm_allocarray( newcols, newrows );
  422. X    for ( row = top; row <= bottom; row++ )
  423. X        for ( col = left; col <= right; col++ )
  424. X        newbits[row-top][col-left] = bits[row][col];
  425. X
  426. X    pbm_writepbm( stdout, newbits, newcols, newrows );
  427. X
  428. X    exit( 0 );
  429. X    }
  430. SHAR_EOF
  431. if test 4241 -ne "`wc -c < 'pbmcrop.c'`"
  432. then
  433.     echo shar: error transmitting "'pbmcrop.c'" '(should have been 4241 characters)'
  434. fi
  435. fi # end of overwriting check
  436. echo shar: extracting "'pbmcrop.1'" '(837 characters)'
  437. if test -f 'pbmcrop.1'
  438. then
  439.     echo shar: will not over-write existing file "'pbmcrop.1'"
  440. else
  441. sed 's/^X//' << \SHAR_EOF > 'pbmcrop.1'
  442. X.TH pbmcrop 1 "31 August 1988"
  443. X.SH NAME
  444. Xpbmcrop - crop a portable bitmap
  445. X.SH SYNOPSIS
  446. Xpbmcrop [-0]/[-w]/[-1]/[-b] [pbmfile]
  447. X.SH DESCRIPTION
  448. XReads a portable bitmap as input.
  449. XRemoves edges that are the background color,
  450. Xand produces a portable bitmap as output.
  451. XBy default, it makes a guess as to what the background
  452. Xcolor is.
  453. XYou can override the default with the -0/-w and -1/-b flags.
  454. X.SH "SEE ALSO"
  455. Xpbmcut(1), pbm(5)
  456. X.SH AUTHOR
  457. XCopyright (C) 1988 by Jef Poskanzer.
  458. X
  459. XPermission to use, copy, modify, and distribute this software and its
  460. Xdocumentation for any purpose and without fee is hereby granted, provided
  461. Xthat the above copyright notice appear in all copies and that both that
  462. Xcopyright notice and this permission notice appear in supporting
  463. Xdocumentation.  This software is provided "as is" without express or
  464. Ximplied warranty.
  465. SHAR_EOF
  466. if test 837 -ne "`wc -c < 'pbmcrop.1'`"
  467. then
  468.     echo shar: error transmitting "'pbmcrop.1'" '(should have been 837 characters)'
  469. fi
  470. fi # end of overwriting check
  471. echo shar: extracting "'pbmtrnspos.c'" '(1332 characters)'
  472. if test -f 'pbmtrnspos.c'
  473. then
  474.     echo shar: will not over-write existing file "'pbmtrnspos.c'"
  475. else
  476. sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.c'
  477. X/* pbmtrnspos.c - read a portable bitmap and transpose it x for y
  478. X**
  479. X** Copyright (C) 1988 by Jef Poskanzer.
  480. X**
  481. X** Permission to use, copy, modify, and distribute this software and its
  482. X** documentation for any purpose and without fee is hereby granted, provided
  483. X** that the above copyright notice appear in all copies and that both that
  484. X** copyright notice and this permission notice appear in supporting
  485. X** documentation.  This software is provided "as is" without express or
  486. X** implied warranty.
  487. X*/
  488. X
  489. X#include <stdio.h>
  490. X#include "pbm.h"
  491. X
  492. Xmain( argc, argv )
  493. Xint argc;
  494. Xchar *argv[];
  495. X    {
  496. X    FILE *ifd;
  497. X    bit **bits, **newbits;
  498. X    int rows, cols, row, col;
  499. X
  500. X    if ( argc > 2 )
  501. X    {
  502. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  503. X    exit( 1 );
  504. X    }
  505. X
  506. X    if ( argc == 2 )
  507. X    {
  508. X        ifd = fopen( argv[1], "r" );
  509. X        if ( ifd == NULL )
  510. X        {
  511. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  512. X        exit( 1 );
  513. X        }
  514. X    }
  515. X    else
  516. X    ifd = stdin;
  517. X
  518. X    bits = pbm_readpbm( ifd, &cols, &rows );
  519. X
  520. X    if ( ifd != stdin )
  521. X    fclose( ifd );
  522. X
  523. X    newbits = pbm_allocarray( rows, cols );    /* note parameter reversal */
  524. X
  525. X    for ( row = 0; row < rows; row++ )
  526. X        for ( col = 0; col < cols; col++ )
  527. X        newbits[col][row] = bits[row][col];
  528. X
  529. X    pbm_writepbm( stdout, newbits, rows, cols );    /* reversed again */
  530. X
  531. X    exit( 0 );
  532. X    }
  533. SHAR_EOF
  534. if test 1332 -ne "`wc -c < 'pbmtrnspos.c'`"
  535. then
  536.     echo shar: error transmitting "'pbmtrnspos.c'" '(should have been 1332 characters)'
  537. fi
  538. fi # end of overwriting check
  539. echo shar: extracting "'pbmtrnspos.1'" '(1035 characters)'
  540. if test -f 'pbmtrnspos.1'
  541. then
  542.     echo shar: will not over-write existing file "'pbmtrnspos.1'"
  543. else
  544. sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.1'
  545. X.TH pbmtrnspos 1 "31 August 1988"
  546. X.SH NAME
  547. Xpbmtrnspos - transpose a portable bitmap x for y
  548. X.SH SYNOPSIS
  549. Xpbmtrnspos [pbmfile]
  550. X.SH DESCRIPTION
  551. XReads a portable bitmap as input.
  552. XTransposes it x for y and produces a portable bitmap as output.
  553. X.PP
  554. XNote that transposition is not rotation, but can be used to produce it.
  555. XFor example, if you wanted a 90 degree clockwise rotation, perhaps for
  556. Xprinting a landscape bitmap on a laser printer, you could
  557. Xdo 'pbmtrnspos | pbmfliplr' or 'pbmfliptb | pbmtrnspos'.
  558. XFor counter-clockwise rotation, you would use the opposite flips.
  559. X.SH "SEE ALSO"
  560. Xpbmfliplr(1), pbmfliptb(1), pbm(5)
  561. X.SH AUTHOR
  562. XCopyright (C) 1988 by Jef Poskanzer.
  563. X
  564. XPermission to use, copy, modify, and distribute this software and its
  565. Xdocumentation for any purpose and without fee is hereby granted, provided
  566. Xthat the above copyright notice appear in all copies and that both that
  567. Xcopyright notice and this permission notice appear in supporting
  568. Xdocumentation.  This software is provided "as is" without express or
  569. Ximplied warranty.
  570. SHAR_EOF
  571. if test 1035 -ne "`wc -c < 'pbmtrnspos.1'`"
  572. then
  573.     echo shar: error transmitting "'pbmtrnspos.1'" '(should have been 1035 characters)'
  574. fi
  575. fi # end of overwriting check
  576. echo shar: extracting "'pbmcut.c'" '(2606 characters)'
  577. if test -f 'pbmcut.c'
  578. then
  579.     echo shar: will not over-write existing file "'pbmcut.c'"
  580. else
  581. sed 's/^X//' << \SHAR_EOF > 'pbmcut.c'
  582. X/* pbmcut.c - cut a rectangle out of a portable bitmap
  583. X**
  584. X** Copyright (C) 1988 by Jef Poskanzer.
  585. X**
  586. X** Permission to use, copy, modify, and distribute this software and its
  587. X** documentation for any purpose and without fee is hereby granted, provided
  588. X** that the above copyright notice appear in all copies and that both that
  589. X** copyright notice and this permission notice appear in supporting
  590. X** documentation.  This software is provided "as is" without express or
  591. X** implied warranty.
  592. X*/
  593. X
  594. X#include <stdio.h>
  595. X#include "pbm.h"
  596. X
  597. Xmain( argc, argv )
  598. Xint argc;
  599. Xchar *argv[];
  600. X    {
  601. X    FILE *ifd;
  602. X    bit **bits, **newbits;
  603. X    int rows, cols, x, y, width, height, row, col;
  604. X    char *usage = "usage:  %s x y width height [pbmfile]\n";
  605. X
  606. X
  607. X    if ( argc < 5 || argc > 6 )
  608. X    {
  609. X    fprintf( stderr, usage, argv[0] );
  610. X    exit( 1 );
  611. X    }
  612. X
  613. X    if ( sscanf( argv[1], "%d", &x ) != 1 )
  614. X    {
  615. X    fprintf( stderr, usage, argv[0] );
  616. X    exit( 1 );
  617. X    }
  618. X    if ( sscanf( argv[2], "%d", &y ) != 1 )
  619. X    {
  620. X    fprintf( stderr, usage, argv[0] );
  621. X    exit( 1 );
  622. X    }
  623. X    if ( sscanf( argv[3], "%d", &width ) != 1 )
  624. X    {
  625. X    fprintf( stderr, usage, argv[0] );
  626. X    exit( 1 );
  627. X    }
  628. X    if ( sscanf( argv[4], "%d", &height ) != 1 )
  629. X    {
  630. X    fprintf( stderr, usage, argv[0] );
  631. X    exit( 1 );
  632. X    }
  633. X
  634. X    if ( x < 0 )
  635. X    {
  636. X    fprintf( stderr, "x is less than 0\n" );
  637. X    exit( 1 );
  638. X    }
  639. X    if ( y < 0 )
  640. X    {
  641. X    fprintf( stderr, "y is less than 0\n" );
  642. X    exit( 1 );
  643. X    }
  644. X    if ( width < 1 )
  645. X    {
  646. X    fprintf( stderr, "width is less than 1\n" );
  647. X    exit( 1 );
  648. X    }
  649. X    if ( height < 1 )
  650. X    {
  651. X    fprintf( stderr, "height is less than 1\n" );
  652. X    exit( 1 );
  653. X    }
  654. X
  655. X    if ( argc == 6 )
  656. X    {
  657. X        ifd = fopen( argv[5], "r" );
  658. X        if ( ifd == NULL )
  659. X        {
  660. X        fprintf( stderr, "%s: can't open.\n", argv[5] );
  661. X        exit( 1 );
  662. X        }
  663. X    }
  664. X    else
  665. X    ifd = stdin;
  666. X
  667. X    bits = pbm_readpbm( ifd, &cols, &rows );
  668. X
  669. X    if ( ifd != stdin )
  670. X    fclose( ifd );
  671. X
  672. X    if ( x >= cols )
  673. X    {
  674. X    fprintf(
  675. X        stderr, "x is too large -- the bitmap has only %d cols\n", cols );
  676. X    exit( 1 );
  677. X    }
  678. X    if ( y >= rows )
  679. X    {
  680. X    fprintf(
  681. X        stderr, "y is too large -- the bitmap has only %d rows\n", rows );
  682. X    exit( 1 );
  683. X    }
  684. X    if ( x + width > cols )
  685. X    {
  686. X    fprintf(
  687. X        stderr, "x + width is too large by %d pixels\n", x + width - cols );
  688. X    exit( 1 );
  689. X    }
  690. X    if ( y + height > rows )
  691. X    {
  692. X    fprintf(
  693. X        stderr, "y + height is too large by %d pixels\n",
  694. X        y + height - rows );
  695. X    exit( 1 );
  696. X    }
  697. X
  698. X    newbits = pbm_allocarray( width, height );
  699. X    for ( row = y; row < y + height; row++ )
  700. X        for ( col = x; col < x + width; col++ )
  701. X        newbits[row-y][col-x] = bits[row][col];
  702. X
  703. X    pbm_writepbm( stdout, newbits, width, height );
  704. X
  705. X    exit( 0 );
  706. X    }
  707. SHAR_EOF
  708. if test 2606 -ne "`wc -c < 'pbmcut.c'`"
  709. then
  710.     echo shar: error transmitting "'pbmcut.c'" '(should have been 2606 characters)'
  711. fi
  712. fi # end of overwriting check
  713. echo shar: extracting "'pbmcut.1'" '(726 characters)'
  714. if test -f 'pbmcut.1'
  715. then
  716.     echo shar: will not over-write existing file "'pbmcut.1'"
  717. else
  718. sed 's/^X//' << \SHAR_EOF > 'pbmcut.1'
  719. X.TH pbmcut 1 "31 August 1988"
  720. X.SH NAME
  721. Xpbmcut - cut a rectangle out of a portable bitmap
  722. X.SH SYNOPSIS
  723. Xpbmcut x y width height [pbmfile]
  724. X.SH DESCRIPTION
  725. XReads a portable bitmap as input.
  726. XExtracts the specified rectangle,
  727. Xand produces a portable bitmap as output.
  728. X.SH "SEE ALSO"
  729. Xpbmcrop(1), pbmpaste(1), pbm(5)
  730. X.SH AUTHOR
  731. XCopyright (C) 1988 by Jef Poskanzer.
  732. X
  733. XPermission to use, copy, modify, and distribute this software and its
  734. Xdocumentation for any purpose and without fee is hereby granted, provided
  735. Xthat the above copyright notice appear in all copies and that both that
  736. Xcopyright notice and this permission notice appear in supporting
  737. Xdocumentation.  This software is provided "as is" without express or
  738. Ximplied warranty.
  739. SHAR_EOF
  740. if test 726 -ne "`wc -c < 'pbmcut.1'`"
  741. then
  742.     echo shar: error transmitting "'pbmcut.1'" '(should have been 726 characters)'
  743. fi
  744. fi # end of overwriting check
  745. echo shar: extracting "'pbmpaste.c'" '(3521 characters)'
  746. if test -f 'pbmpaste.c'
  747. then
  748.     echo shar: will not over-write existing file "'pbmpaste.c'"
  749. else
  750. sed 's/^X//' << \SHAR_EOF > 'pbmpaste.c'
  751. X/* pbmpaste.c - paste a rectangle into a portable bitmap
  752. X**
  753. X** Copyright (C) 1988 by Jef Poskanzer.
  754. X**
  755. X** Permission to use, copy, modify, and distribute this software and its
  756. X** documentation for any purpose and without fee is hereby granted, provided
  757. X** that the above copyright notice appear in all copies and that both that
  758. X** copyright notice and this permission notice appear in supporting
  759. X** documentation.  This software is provided "as is" without express or
  760. X** implied warranty.
  761. X*/
  762. X
  763. X#include <stdio.h>
  764. X#include "pbm.h"
  765. X
  766. Xmain( argc, argv )
  767. Xint argc;
  768. Xchar *argv[];
  769. X    {
  770. X    FILE *ifd;
  771. X    bit **bits1, **bits2;
  772. X    int argn, rows1, cols1, x, y, rows2, cols2, row, col;
  773. X    char function;
  774. X    char *usage = "usage:  %s [-r]/[-o]/[-a]/[-x] frompbmfile x y [intopbmfile]\n";
  775. X
  776. X    argn = 1;
  777. X    function = 'r';
  778. X
  779. X    /* Check for flags. */
  780. X    if ( argn < argc )
  781. X    {
  782. X    if ( argv[argn][0] == '-' )
  783. X        {
  784. X        if ( ( argv[argn][1] == 'r' || argv[argn][1] == 'R' ||
  785. X           argv[argn][1] == 'o' || argv[argn][1] == 'O' ||
  786. X           argv[argn][1] == 'a' || argv[argn][1] == 'A' ||
  787. X           argv[argn][1] == 'x' || argv[argn][1] == 'X' ) &&
  788. X         argv[argn][2] == '\0' )
  789. X        function = argv[argn][1];
  790. X        else
  791. X        {
  792. X        fprintf( stderr, usage, argv[0] );
  793. X        exit( 1 );
  794. X        }
  795. X        argn++;
  796. X        }
  797. X    }
  798. X
  799. X    if ( argn == argc )
  800. X    {
  801. X    fprintf( stderr, usage, argv[0] );
  802. X    exit( 1 );
  803. X    }
  804. X    ifd = fopen( argv[argn], "r" );
  805. X    if ( ifd == NULL )
  806. X    {
  807. X    fprintf( stderr, "%s: can't open.\n", argv[argn] );
  808. X    exit( 1 );
  809. X    }
  810. X    bits1 = pbm_readpbm( ifd, &cols1, &rows1 );
  811. X    fclose( ifd );
  812. X    argn++;
  813. X
  814. X    if ( argn == argc )
  815. X    {
  816. X    fprintf( stderr, usage, argv[0] );
  817. X    exit( 1 );
  818. X    }
  819. X    if ( sscanf( argv[argn], "%d", &x ) != 1 )
  820. X    {
  821. X    fprintf( stderr, usage, argv[0] );
  822. X    exit( 1 );
  823. X    }
  824. X    argn++;
  825. X    if ( argn == argc )
  826. X    {
  827. X    fprintf( stderr, usage, argv[0] );
  828. X    exit( 1 );
  829. X    }
  830. X    if ( sscanf( argv[argn], "%d", &y ) != 1 )
  831. X    {
  832. X    fprintf( stderr, usage, argv[0] );
  833. X    exit( 1 );
  834. X    }
  835. X    argn++;
  836. X
  837. X    if ( x < 0 )
  838. X    {
  839. X    fprintf( stderr, "x is less than 0\n" );
  840. X    exit( 1 );
  841. X    }
  842. X    if ( y < 0 )
  843. X    {
  844. X    fprintf( stderr, "y is less than 0\n" );
  845. X    exit( 1 );
  846. X    }
  847. X
  848. X    if ( argn == argc )
  849. X    ifd = stdin;
  850. X    else
  851. X    {
  852. X        ifd = fopen( argv[argn], "r" );
  853. X        if ( ifd == NULL )
  854. X        {
  855. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  856. X        exit( 1 );
  857. X        }
  858. X    argn++;
  859. X    }
  860. X    bits2 = pbm_readpbm( ifd, &cols2, &rows2 );
  861. X    if ( ifd != stdin )
  862. X    fclose( ifd );
  863. X
  864. X    if ( x >= cols2 )
  865. X    {
  866. X    fprintf(
  867. X        stderr, "x is too large -- the second bitmap has only %d cols\n",
  868. X        cols2 );
  869. X    exit( 1 );
  870. X    }
  871. X    if ( y >= rows2 )
  872. X    {
  873. X    fprintf(
  874. X        stderr, "y is too large -- the second bitmap has only %d rows\n",
  875. X        rows2 );
  876. X    exit( 1 );
  877. X    }
  878. X    if ( x + cols1 > cols2 )
  879. X    {
  880. X    fprintf(
  881. X        stderr, "x + width is too large by %d pixels\n",
  882. X        x + cols1 - cols2 );
  883. X    exit( 1 );
  884. X    }
  885. X    if ( y + rows1 > rows2 )
  886. X    {
  887. X    fprintf(
  888. X        stderr, "y + height is too large by %d pixels\n",
  889. X        y + rows1 - rows2 );
  890. X    exit( 1 );
  891. X    }
  892. X
  893. X    if ( argn != argc )
  894. X    {
  895. X    fprintf( stderr, usage, argv[0] );
  896. X    exit( 1 );
  897. X    }
  898. X
  899. X    for ( row = 0; row < rows1; row++ )
  900. X        for ( col = 0; col < cols1; col++ )
  901. X        switch ( function )
  902. X        {
  903. X        case 'r':
  904. X        case 'R':
  905. X        bits2[row+y][col+x] = bits1[row][col];
  906. X        break;
  907. X
  908. X        case 'o':
  909. X        case 'O':
  910. X        bits2[row+y][col+x] |= bits1[row][col];
  911. X        break;
  912. X
  913. X        case 'a':
  914. X        case 'A':
  915. X        bits2[row+y][col+x] &= bits1[row][col];
  916. X        break;
  917. X
  918. X        case 'x':
  919. X        case 'X':
  920. X        bits2[row+y][col+x] ^= bits1[row][col];
  921. X        break;
  922. X        }
  923. X
  924. X    pbm_writepbm( stdout, bits2, cols2, rows2 );
  925. X
  926. X    exit( 0 );
  927. X    }
  928. SHAR_EOF
  929. if test 3521 -ne "`wc -c < 'pbmpaste.c'`"
  930. then
  931.     echo shar: error transmitting "'pbmpaste.c'" '(should have been 3521 characters)'
  932. fi
  933. fi # end of overwriting check
  934. echo shar: extracting "'pbmpaste.1'" '(1311 characters)'
  935. if test -f 'pbmpaste.1'
  936. then
  937.     echo shar: will not over-write existing file "'pbmpaste.1'"
  938. else
  939. sed 's/^X//' << \SHAR_EOF > 'pbmpaste.1'
  940. X.TH pbmpaste 1 "06 April 1988"
  941. X.SH NAME
  942. Xpbmpaste - paste a rectangle into a portable bitmap
  943. X.SH SYNOPSIS
  944. Xpbmpaste [-r]/[-o]/[-a]/[-x] frompbmfile x y [intopbmfile]
  945. X.SH DESCRIPTION
  946. XReads two portable bitmaps as input.
  947. XInserts the first bitmap into the second at the specified location,
  948. Xand produces a portable bitmap the same size as the second as output.
  949. XIf the second bitmap is not specified, it is read from stdin.
  950. X.PP
  951. XThe -r/-o/-a/-x flags specify the logical operation to use when doing
  952. Xthe paste.
  953. XThey stand for Replace, Or, And, and Xor, respectively.
  954. XThe default is replace.
  955. X.PP
  956. XThis tool is most useful in combination with pbmcut(1).
  957. XFor instance, if you want to edit a small segment of a large
  958. Xbitmap, and your bitmap editor is TOO STUPID to edit the
  959. Xlarge bitmap, you can cut out the segment you are interested in,
  960. Xedit it, and then paste it back in.
  961. X.SH "SEE ALSO"
  962. Xpbmcut(1), pbm(5)
  963. X.SH AUTHOR
  964. XCopyright (C) 1988 by Jef Poskanzer.
  965. X
  966. XPermission to use, copy, modify, and distribute this software and its
  967. Xdocumentation for any purpose and without fee is hereby granted, provided
  968. Xthat the above copyright notice appear in all copies and that both that
  969. Xcopyright notice and this permission notice appear in supporting
  970. Xdocumentation.  This software is provided "as is" without express or
  971. Ximplied warranty.
  972. SHAR_EOF
  973. if test 1311 -ne "`wc -c < 'pbmpaste.1'`"
  974. then
  975.     echo shar: error transmitting "'pbmpaste.1'" '(should have been 1311 characters)'
  976. fi
  977. fi # end of overwriting check
  978. echo shar: extracting "'xxxtopbm.c'" '(2375 characters)'
  979. if test -f 'xxxtopbm.c'
  980. then
  981.     echo shar: will not over-write existing file "'xxxtopbm.c'"
  982. else
  983. sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.c'
  984. X/* xxxtopbm.c - read an xxx bitmap and write a portable bitmap
  985. X**
  986. X** Copyright (C) 1988 by Jef Poskanzer.
  987. X**
  988. X** Permission to use, copy, modify, and distribute this software and its
  989. X** documentation for any purpose and without fee is hereby granted, provided
  990. X** that the above copyright notice appear in all copies and that both that
  991. X** copyright notice and this permission notice appear in supporting
  992. X** documentation.  This software is provided "as is" without express or
  993. X** implied warranty.
  994. X*/
  995. X
  996. X#include <stdio.h>
  997. X#include "pbm.h"
  998. X
  999. Xmain( argc, argv )
  1000. Xint argc;
  1001. Xchar *argv[];
  1002. X    {
  1003. X    FILE *ifd;
  1004. X    bit **bits, getbit();
  1005. X    int rows, cols, padright, row, col, subcol;
  1006. X
  1007. X    if ( argc > 2 )
  1008. X    {
  1009. X    fprintf( stderr, "usage:  %s [xxxfile]\n", argv[0] );
  1010. X    exit( 1 );
  1011. X    }
  1012. X
  1013. X    if ( argc == 2 )
  1014. X    {
  1015. X        ifd = fopen( argv[1], "r" );
  1016. X        if ( ifd == NULL )
  1017. X        {
  1018. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1019. X        exit( 1 );
  1020. X        }
  1021. X    }
  1022. X    else
  1023. X    ifd = stdin;
  1024. X
  1025. X    getinit( ifd, &cols, &rows );
  1026. X
  1027. X    bits = pbm_allocarray( cols, rows );
  1028. X
  1029. X    /* Compute padding to round cols up to the next multiple of 16. */
  1030. X    padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
  1031. X
  1032. X    for ( row = 0; row < rows; row++ )
  1033. X    {
  1034. X    /* Get data, bit-reversed within each byte. */
  1035. X        for ( col = 0; col < cols; col += 8 )
  1036. X        for ( subcol = col + 7; subcol >= col; subcol-- )
  1037. X        bits[row][subcol] = getbit( ifd );
  1038. X    /* Discard line padding */
  1039. X        for ( col = 0; col < padright; col ++ )
  1040. X        (void) getbit( ifd );
  1041. X    }
  1042. X
  1043. X    if ( ifd != stdin )
  1044. X    fclose( ifd );
  1045. X    
  1046. X    pbm_writepbm( stdout, bits, cols, rows );
  1047. X
  1048. X    exit( 0 );
  1049. X    }
  1050. X
  1051. X
  1052. Xint item, bitsperitem, bitshift;
  1053. X
  1054. Xgetinit( file, colp, rowp )
  1055. XFILE *file;
  1056. Xint *colp, *rowp;
  1057. X    {
  1058. X    int i;
  1059. X
  1060. X    if ( getc( file ) != 109 )
  1061. X    {
  1062. X    fprintf( stderr, "Bad magic number 1.\n" );
  1063. X    exit( 1 );
  1064. X    }
  1065. X    if ( getc( file ) != 1 )
  1066. X    {
  1067. X    fprintf( stderr, "Bad magic number 2.\n" );
  1068. X    exit( 1 );
  1069. X    }
  1070. X    *colp = getc( file );
  1071. X    *colp += getc( file ) << 8;
  1072. X    *rowp = getc( file );
  1073. X    *rowp += getc( file ) << 8;
  1074. X    bitsperitem = 8;
  1075. X
  1076. X    /* Junk rest of header. */
  1077. X    for ( i = 0; i < 2; i++ )
  1078. X        (void) getc( file );
  1079. X    }
  1080. X
  1081. Xbit
  1082. Xgetbit( file )
  1083. XFILE *file;
  1084. X    {
  1085. X    bit b;
  1086. X
  1087. X    if ( bitsperitem == 8 )
  1088. X    {
  1089. X    item = getc( file );
  1090. X    bitsperitem = 0;
  1091. X    bitshift = 7;
  1092. X    }
  1093. X    bitsperitem++;
  1094. X    b = ( item >> bitshift) & 1;
  1095. X    bitshift--;
  1096. X    return b;
  1097. X    }
  1098. SHAR_EOF
  1099. if test 2375 -ne "`wc -c < 'xxxtopbm.c'`"
  1100. then
  1101.     echo shar: error transmitting "'xxxtopbm.c'" '(should have been 2375 characters)'
  1102. fi
  1103. fi # end of overwriting check
  1104. echo shar: extracting "'xxxtopbm.1'" '(922 characters)'
  1105. if test -f 'xxxtopbm.1'
  1106. then
  1107.     echo shar: will not over-write existing file "'xxxtopbm.1'"
  1108. else
  1109. sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.1'
  1110. X.TH xxxtopbm 1 "28 August 1988"
  1111. X.SH NAME
  1112. Xxxxtopbm - convert "xxx" bitmaps into portable bitmaps
  1113. X.SH SYNOPSIS
  1114. Xxxxtopbm [xxxfile]
  1115. X.SH DESCRIPTION
  1116. XReads an "xxx" bitmap as input.
  1117. XProduces a portable bitmap as output.
  1118. X.LP
  1119. X"xxx" bitmaps are the unknown and undocumented format found on
  1120. Xucbvax.Berkeley.Edu in the directory pub/xbackgrounds.
  1121. XThe arrangement of the bits is the same as for Sun rasterfiles, but
  1122. Xthe headers are completely different.
  1123. X.LP
  1124. XNote that there is no pbmtoxxx tool.
  1125. X.SH "SEE ALSO"
  1126. Xpbm(5)
  1127. X.SH AUTHOR
  1128. XCopyright (C) 1988 by Jef Poskanzer.
  1129. X
  1130. XPermission to use, copy, modify, and distribute this software and its
  1131. Xdocumentation for any purpose and without fee is hereby granted, provided
  1132. Xthat the above copyright notice appear in all copies and that both that
  1133. Xcopyright notice and this permission notice appear in supporting
  1134. Xdocumentation.  This software is provided "as is" without express or
  1135. Ximplied warranty.
  1136. SHAR_EOF
  1137. if test 922 -ne "`wc -c < 'xxxtopbm.1'`"
  1138. then
  1139.     echo shar: error transmitting "'xxxtopbm.1'" '(should have been 922 characters)'
  1140. fi
  1141. fi # end of overwriting check
  1142. echo shar: extracting "'pbmenlarge.c'" '(1776 characters)'
  1143. if test -f 'pbmenlarge.c'
  1144. then
  1145.     echo shar: will not over-write existing file "'pbmenlarge.c'"
  1146. else
  1147. sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.c'
  1148. X/* pbmenlarge.c - read a portable bitmap and enlarge it N times
  1149. X**
  1150. X** Copyright (C) 1988 by Jef Poskanzer.
  1151. X**
  1152. X** Permission to use, copy, modify, and distribute this software and its
  1153. X** documentation for any purpose and without fee is hereby granted, provided
  1154. X** that the above copyright notice appear in all copies and that both that
  1155. X** copyright notice and this permission notice appear in supporting
  1156. X** documentation.  This software is provided "as is" without express or
  1157. X** implied warranty.
  1158. X*/
  1159. X
  1160. X#include <stdio.h>
  1161. X#include "pbm.h"
  1162. X
  1163. Xmain( argc, argv )
  1164. Xint argc;
  1165. Xchar *argv[];
  1166. X    {
  1167. X    FILE *ifd;
  1168. X    bit **bits, **newbits;
  1169. X    int argn, n, rows, cols, row, col, subrow, subcol;
  1170. X    char *usage = "usage:  %s [-N] [pbmfile]\n";
  1171. X
  1172. X    argn = 1;
  1173. X    n = 2;
  1174. X
  1175. X    if ( argn < argc )
  1176. X    {
  1177. X    if ( argv[argn][0] == '-' )
  1178. X        {
  1179. X        if ( sscanf( &(argv[argn][1]), "%d", &n ) != 1 )
  1180. X        {
  1181. X        fprintf( stderr, usage, argv[0] );
  1182. X        exit( 1 );
  1183. X        }
  1184. X        if ( n < 2 )
  1185. X        {
  1186. X        fprintf( stderr, usage, argv[0] );
  1187. X        exit( 1 );
  1188. X        }
  1189. X        argn++;
  1190. X        }
  1191. X    }
  1192. X
  1193. X    if ( argn == argc )
  1194. X    ifd = stdin;
  1195. X    else
  1196. X    {
  1197. X    ifd = fopen( argv[argn], "r" );
  1198. X    if ( ifd == NULL )
  1199. X        {
  1200. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  1201. X        exit( 1 );
  1202. X        }
  1203. X    argn++;
  1204. X    }
  1205. X
  1206. X    if ( argn != argc )
  1207. X    {
  1208. X    fprintf( stderr, usage, argv[0] );
  1209. X    exit( 1 );
  1210. X    }
  1211. X
  1212. X    bits = pbm_readpbm( ifd, &cols, &rows );
  1213. X    if ( ifd != stdin )
  1214. X    fclose( ifd );
  1215. X
  1216. X    newbits = pbm_allocarray( cols * n, rows * n );
  1217. X
  1218. X    for ( row = 0; row < rows; row++ )
  1219. X        for ( col = 0; col < cols; col++ )
  1220. X        for ( subrow = 0; subrow < n; subrow++ )
  1221. X        for ( subcol = 0; subcol < n; subcol++ )
  1222. X            newbits[row * n + subrow][col * n + subcol] =
  1223. X            bits[row][col];
  1224. X
  1225. X    pbm_writepbm( stdout, newbits, cols * n, rows * n );
  1226. X
  1227. X    exit( 0 );
  1228. X    }
  1229. SHAR_EOF
  1230. if test 1776 -ne "`wc -c < 'pbmenlarge.c'`"
  1231. then
  1232.     echo shar: error transmitting "'pbmenlarge.c'" '(should have been 1776 characters)'
  1233. fi
  1234. fi # end of overwriting check
  1235. echo shar: extracting "'pbmenlarge.1'" '(735 characters)'
  1236. if test -f 'pbmenlarge.1'
  1237. then
  1238.     echo shar: will not over-write existing file "'pbmenlarge.1'"
  1239. else
  1240. sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.1'
  1241. X.TH pbmenlarge 1 "29 February 1988"
  1242. X.SH NAME
  1243. Xpbmenlarge - read a portable bitmap and enlarge it N times
  1244. X.SH SYNOPSIS
  1245. Xpbmenlarge [-N] [pbmfile]
  1246. X.SH DESCRIPTION
  1247. XReads a portable bitmap as input.
  1248. XReplicates its bits N times, and produces a portable bitmap as output.
  1249. XThe default enlargement is two.
  1250. X.SH "SEE ALSO"
  1251. Xpbm(5)
  1252. X.SH AUTHOR
  1253. XCopyright (C) 1988 by Jef Poskanzer.
  1254. X
  1255. XPermission to use, copy, modify, and distribute this software and its
  1256. Xdocumentation for any purpose and without fee is hereby granted, provided
  1257. Xthat the above copyright notice appear in all copies and that both that
  1258. Xcopyright notice and this permission notice appear in supporting
  1259. Xdocumentation.  This software is provided "as is" without express or
  1260. Ximplied warranty.
  1261. SHAR_EOF
  1262. if test 735 -ne "`wc -c < 'pbmenlarge.1'`"
  1263. then
  1264.     echo shar: error transmitting "'pbmenlarge.1'" '(should have been 735 characters)'
  1265. fi
  1266. fi # end of overwriting check
  1267. echo shar: extracting "'pbmmake.c'" '(2226 characters)'
  1268. if test -f 'pbmmake.c'
  1269. then
  1270.     echo shar: will not over-write existing file "'pbmmake.c'"
  1271. else
  1272. sed 's/^X//' << \SHAR_EOF > 'pbmmake.c'
  1273. X/* pbmmake.c - create a blank bitmap of a specified size
  1274. X**
  1275. X** Copyright (C) 1988 by Jef Poskanzer.
  1276. X**
  1277. X** Permission to use, copy, modify, and distribute this software and its
  1278. X** documentation for any purpose and without fee is hereby granted, provided
  1279. X** that the above copyright notice appear in all copies and that both that
  1280. X** copyright notice and this permission notice appear in supporting
  1281. X** documentation.  This software is provided "as is" without express or
  1282. X** implied warranty.
  1283. X*/
  1284. X
  1285. X#include <stdio.h>
  1286. X#include "pbm.h"
  1287. X
  1288. Xmain( argc, argv )
  1289. Xint argc;
  1290. Xchar *argv[];
  1291. X    {
  1292. X    bit color, gray, rowcolor, **bits;
  1293. X    int argn, rows, cols, row, col;
  1294. X    char *usage = "usage:  %s [-0]/[-w]/[-1]/[-b]/[-g] <width> <height>\n";
  1295. X
  1296. X    argn = 1;
  1297. X    color = 0;
  1298. X    gray = 0;
  1299. X
  1300. X    /* Check for flags. */
  1301. X    if ( argn < argc )
  1302. X    {
  1303. X    if ( argv[argn][0] == '-' )
  1304. X        {
  1305. X        if ( ( argv[argn][1] == '0' || argv[argn][1] == 'w' ||
  1306. X           argv[argn][1] == 'W' ) && argv[argn][2] == '\0' )
  1307. X        color = 0;
  1308. X        else if ( ( argv[argn][1] == '1' || argv[argn][1] == 'b' ||
  1309. X            argv[argn][1] == 'B' ) && argv[argn][2] == '\0' )
  1310. X        color = 1;
  1311. X        else if ( ( argv[argn][1] == 'g' || argv[argn][1] == 'G' ) &&
  1312. X              argv[argn][2] == '\0' )
  1313. X        gray = 1;
  1314. X        else
  1315. X        {
  1316. X        fprintf( stderr, usage, argv[0] );
  1317. X        exit( 1 );
  1318. X        }
  1319. X        argn++;
  1320. X        }
  1321. X    }
  1322. X
  1323. X    if ( argn == argc )
  1324. X    {
  1325. X    fprintf( stderr, usage, argv[0] );
  1326. X    exit( 1 );
  1327. X    }
  1328. X    if ( sscanf( argv[argn], "%d", &cols ) != 1 )
  1329. X    {
  1330. X    fprintf( stderr, usage, argv[0] );
  1331. X    exit( 1 );
  1332. X    }
  1333. X    argn++;
  1334. X    if ( argn == argc )
  1335. X    {
  1336. X    fprintf( stderr, usage, argv[0] );
  1337. X    exit( 1 );
  1338. X    }
  1339. X    if ( sscanf( argv[argn], "%d", &rows ) != 1 )
  1340. X    {
  1341. X    fprintf( stderr, usage, argv[0] );
  1342. X    exit( 1 );
  1343. X    }
  1344. X    argn++;
  1345. X
  1346. X    if ( argn != argc )
  1347. X    {
  1348. X    fprintf( stderr, usage, argv[0] );
  1349. X    exit( 1 );
  1350. X    }
  1351. X
  1352. X    bits = pbm_allocarray( cols, rows );
  1353. X
  1354. X    if ( gray )
  1355. X    rowcolor = 0;  /* arbitrarily make the corner white */
  1356. X    for ( row = 0; row < rows; row++ )
  1357. X    {
  1358. X    if ( gray )
  1359. X        {
  1360. X        color = rowcolor;
  1361. X        rowcolor = 1 - rowcolor;
  1362. X        }
  1363. X        for ( col = 0; col < cols; col++ )
  1364. X        {
  1365. X        bits[row][col] = color;
  1366. X        if ( gray )
  1367. X        color = 1 - color;
  1368. X        }
  1369. X    }
  1370. X
  1371. X    pbm_writepbm( stdout, bits, cols, rows );
  1372. X
  1373. X    exit( 0 );
  1374. X    }
  1375. SHAR_EOF
  1376. if test 2226 -ne "`wc -c < 'pbmmake.c'`"
  1377. then
  1378.     echo shar: error transmitting "'pbmmake.c'" '(should have been 2226 characters)'
  1379. fi
  1380. fi # end of overwriting check
  1381. echo shar: extracting "'pbmmake.1'" '(870 characters)'
  1382. if test -f 'pbmmake.1'
  1383. then
  1384.     echo shar: will not over-write existing file "'pbmmake.1'"
  1385. else
  1386. sed 's/^X//' << \SHAR_EOF > 'pbmmake.1'
  1387. X.TH pbmmake 1 "16 May 1988"
  1388. X.SH NAME
  1389. Xpbmmake - create a blank bitmap of a specified size
  1390. X.SH SYNOPSIS
  1391. Xpbmmake [-0]/[-w]/[-1]/[-b]/[-g] <width> <height>
  1392. X.SH DESCRIPTION
  1393. XProduces a portable bitmap of the specified width and height.
  1394. XThe color defaults to 0/white.
  1395. X.LP
  1396. XIn addition to the usual -w/-0 for white and -b/-1 for black, this program
  1397. Ximplements -g for gray.
  1398. XThis gives a simple 50% gray pattern with 1's and 0's alternating.
  1399. X.SH "SEE ALSO"
  1400. Xpbm(5)
  1401. X.SH AUTHOR
  1402. XCopyright (C) 1988 by Jef Poskanzer.
  1403. X
  1404. XPermission to use, copy, modify, and distribute this software and its
  1405. Xdocumentation for any purpose and without fee is hereby granted, provided
  1406. Xthat the above copyright notice appear in all copies and that both that
  1407. Xcopyright notice and this permission notice appear in supporting
  1408. Xdocumentation.  This software is provided "as is" without express or
  1409. Ximplied warranty.
  1410. SHAR_EOF
  1411. if test 870 -ne "`wc -c < 'pbmmake.1'`"
  1412. then
  1413.     echo shar: error transmitting "'pbmmake.1'" '(should have been 870 characters)'
  1414. fi
  1415. fi # end of overwriting check
  1416. echo shar: extracting "'pbmtolj.c'" '(3054 characters)'
  1417. if test -f 'pbmtolj.c'
  1418. then
  1419.     echo shar: will not over-write existing file "'pbmtolj.c'"
  1420. else
  1421. sed 's/^X//' << \SHAR_EOF > 'pbmtolj.c'
  1422. X/* pbmtolj.c - read a portable bitmap and produce a LaserJet bitmap file
  1423. X**    
  1424. X**    based on pbmtops.c
  1425. X**
  1426. X**    Michael Haberler HP Vienna mah@hpuviea.uucp
  1427. X**                   mcvax!tuvie!mah
  1428. X**    misfeatures: 
  1429. X**        no positioning
  1430. X**
  1431. X** Copyright (C) 1988 by Jef Poskanzer and Michael Haberler.
  1432. X**
  1433. X** Permission to use, copy, modify, and distribute this software and its
  1434. X** documentation for any purpose and without fee is hereby granted, provided
  1435. X** that the above copyright notice appear in all copies and that both that
  1436. X** copyright notice and this permission notice appear in supporting
  1437. X** documentation.  This software is provided "as is" without express or
  1438. X** implied warranty.
  1439. X*/
  1440. X
  1441. X#include <stdio.h>
  1442. X#ifdef    OS_SYSV
  1443. X#include <string.h>
  1444. X#else    OS_SYSV
  1445. X#include <strings.h>
  1446. X#endif    OS_SYSV
  1447. X#include "pbm.h"
  1448. X
  1449. Xint dpi = 75;
  1450. X    
  1451. Xmain( argc, argv )
  1452. Xint argc;
  1453. Xchar *argv[];
  1454. X    {
  1455. X    FILE *ifd;
  1456. X    bit **bits;
  1457. X    int argn, rows, cols, rucols, padright, row, col;
  1458. X    char ch;
  1459. X    char *usage = 
  1460. X"usage:  %s [-r resolution] [pbmfile]\n\t\
  1461. Xresolution = [75|100|150|300] (dpi)\n";
  1462. X
  1463. X    argn = 1;
  1464. X
  1465. X    /* Check for flags. */
  1466. X    if ( argc > argn )
  1467. X    {
  1468. X    if ( argv[argn][0] == '-' )
  1469. X        {
  1470. X        if ( strcmp( argv[argn], "-r" ) == 0 )
  1471. X        {
  1472. X        if ( argc == argn + 1 )
  1473. X            {
  1474. X            fprintf( stderr, usage, argv[0] );
  1475. X            exit( 1 );
  1476. X            }
  1477. X        if ( sscanf( argv[argn+1], "%d", &dpi ) != 1 )
  1478. X            {
  1479. X            fprintf( stderr, usage, argv[0] );
  1480. X            exit( 1 );
  1481. X            }
  1482. X        argn += 2;
  1483. X        }
  1484. X        else
  1485. X        {
  1486. X        fprintf( stderr, usage, argv[0] );
  1487. X        exit( 1 );
  1488. X        }
  1489. X        }
  1490. X    }
  1491. X
  1492. X    if ( argc > argn + 1 )
  1493. X    {
  1494. X    fprintf( stderr, usage, argv[0] );
  1495. X    exit( 1 );
  1496. X    }
  1497. X
  1498. X    if ( argc == argn + 1 )
  1499. X    {
  1500. X        ifd = fopen( argv[argn], "r" );
  1501. X        if ( ifd == NULL )
  1502. X        {
  1503. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  1504. X        exit( 1 );
  1505. X        }
  1506. X    }
  1507. X    else
  1508. X    ifd = stdin;
  1509. X
  1510. X    bits = pbm_readpbm( ifd, &cols, &rows );
  1511. X
  1512. X    if ( ifd != stdin )
  1513. X    fclose( ifd );
  1514. X
  1515. X    /* Round cols up to the nearest multiple of 8. */
  1516. X    rucols = ( cols + 7 ) / 8;
  1517. X    rucols = rucols * 8;
  1518. X    padright = rucols - cols;
  1519. X
  1520. X    putinit( );
  1521. X    for ( row = 0; row < rows; row++ )
  1522. X    {
  1523. X    /* Transfer raster graphics */
  1524. X     printf("\033*b%dW",rucols/8);
  1525. X        for ( col = 0; col < cols; col++ )
  1526. X        putbit( bits[row][col] );
  1527. X    for ( col = 0; col < padright; col++ )
  1528. X        putbit( 0 );
  1529. X        }
  1530. X    putrest( );
  1531. X
  1532. X    exit( 0 );
  1533. X    }
  1534. X
  1535. X
  1536. Xint item, bitsperitem, bitshift, itemsperline, firstitem;
  1537. X
  1538. Xputinit( )
  1539. X    {
  1540. X    /* Set raster graphics resolution */
  1541. X    printf("\033*t%dR",dpi);
  1542. X
  1543. X    /* Start raster graphics, relative adressing */
  1544. X    printf("\033*r1A");
  1545. X
  1546. X    itemsperline = 0;
  1547. X    bitsperitem = 1;
  1548. X    item = 0;
  1549. X    bitshift = 7;
  1550. X    firstitem = 1;
  1551. X    }
  1552. X
  1553. Xputbit( b )
  1554. Xbit b;
  1555. X    {
  1556. X    if ( bitsperitem == 8 ) {
  1557. X    putitem( );
  1558. X        bitshift = 7;
  1559. X    }
  1560. X    if ( b )
  1561. X    item += 1 << bitshift;
  1562. X    bitsperitem++;
  1563. X    bitshift--;
  1564. X    }
  1565. X
  1566. Xputrest( )
  1567. X    {
  1568. X    if ( bitsperitem > 1 )
  1569. X    putitem( );
  1570. X
  1571. X    /* end raster graphics */
  1572. X    printf( "\033*rB" );
  1573. X    }
  1574. X
  1575. Xputitem( )
  1576. X    {
  1577. X    putchar( item );
  1578. X    bitsperitem = 0;
  1579. X    item = 0;
  1580. X    }
  1581. SHAR_EOF
  1582. if test 3054 -ne "`wc -c < 'pbmtolj.c'`"
  1583. then
  1584.     echo shar: error transmitting "'pbmtolj.c'" '(should have been 3054 characters)'
  1585. fi
  1586. fi # end of overwriting check
  1587. echo shar: extracting "'pbmtolj.1'" '(862 characters)'
  1588. if test -f 'pbmtolj.1'
  1589. then
  1590.     echo shar: will not over-write existing file "'pbmtolj.1'"
  1591. else
  1592. sed 's/^X//' << \SHAR_EOF > 'pbmtolj.1'
  1593. X.TH pbmtolj 1 "29 August 1988"
  1594. X.SH NAME
  1595. Xpbmtolj - convert portable bitmaps into HP LaserJet
  1596. X.SH SYNOPSIS
  1597. Xpbmtolj [ -r <resolution> ] [ <pbmfile> ]
  1598. X.SH DESCRIPTION
  1599. XReads a portable bitmap as input.
  1600. XProduces HP LaserJet data as output.
  1601. X.LP
  1602. XThe -r flag specifies the resolution of the output device, in dpi.
  1603. XTypical values are 75, 100, 150, 300.
  1604. XThe default is 75.
  1605. X.LP
  1606. XNote that there is no ljtopbm tool.
  1607. X.SH "SEE ALSO"
  1608. Xpbm(5)
  1609. X.SH AUTHOR
  1610. XCopyright (C) 1988 by Jef Poskanzer and Michael Haberler.
  1611. X
  1612. XPermission to use, copy, modify, and distribute this software and its
  1613. Xdocumentation for any purpose and without fee is hereby granted, provided
  1614. Xthat the above copyright notice appear in all copies and that both that
  1615. Xcopyright notice and this permission notice appear in supporting
  1616. Xdocumentation.  This software is provided "as is" without express or
  1617. Ximplied warranty.
  1618. SHAR_EOF
  1619. if test 862 -ne "`wc -c < 'pbmtolj.1'`"
  1620. then
  1621.     echo shar: error transmitting "'pbmtolj.1'" '(should have been 862 characters)'
  1622. fi
  1623. fi # end of overwriting check
  1624. echo shar: extracting "'pbmtomacp.c'" '(6598 characters)'
  1625. if test -f 'pbmtomacp.c'
  1626. then
  1627.     echo shar: will not over-write existing file "'pbmtomacp.c'"
  1628. else
  1629. sed 's/^X//' << \SHAR_EOF > 'pbmtomacp.c'
  1630. X/* pbmtomacp.c - read a portable bitmap and produce a MacPaint bitmap file
  1631. X**
  1632. X** Copyright (C) 1988 by Douwe vand der Schaaf.
  1633. X**
  1634. X** Permission to use, copy, modify, and distribute this software and its
  1635. X** documentation for any purpose and without fee is hereby granted, provided
  1636. X** that the above copyright notice appear in all copies and that both that
  1637. X** copyright notice and this permission notice appear in supporting
  1638. X** documentation.  This software is provided "as is" without express or
  1639. X** implied warranty.
  1640. X*/
  1641. X
  1642. X#include <stdio.h>
  1643. X#include "pbm.h"
  1644. X#include "macp.h"
  1645. X
  1646. X#define TRUE        1
  1647. X#define FALSE        0
  1648. X#define EQUAL        1
  1649. X#define UNEQUAL        0
  1650. X
  1651. XFILE *fdout;
  1652. Xchar *Program;
  1653. Xchar *usage =
  1654. X    "usage:  %s [-l left] [-r right] [-b bottom] [-t top] [pbmfile]\n";
  1655. X
  1656. Xextern int optind;
  1657. Xextern char *optarg;
  1658. X
  1659. Xmain(argc, argv)
  1660. Xint argc;
  1661. Xchar *argv[];
  1662. X{ int c;
  1663. X  FILE *ifd;
  1664. X  bit **bits, **bitsr;
  1665. X  int rows, cols;
  1666. X  int left,bottom,right,top;
  1667. X  int lflg, rflg, tflg, bflg, errflg;
  1668. X  char name[100];
  1669. Xint i,j;
  1670. X
  1671. X  fdout = stdout;
  1672. X  Program = argv[0];
  1673. X  errflg = lflg = rflg = tflg = bflg = 0;
  1674. X  if( argc > 1 )
  1675. X  { while( ( c = getopt( argc, argv, "l:r:t:b:" ) ) != EOF )
  1676. X    switch(c)
  1677. X    {
  1678. Xcase 'l':
  1679. X      lflg++;
  1680. X      left = atoi( optarg );
  1681. X      break;
  1682. X
  1683. Xcase 'r':
  1684. X      rflg++;
  1685. X      right = atoi( optarg );
  1686. X      break;
  1687. X
  1688. Xcase 't':
  1689. X      tflg++;
  1690. X      top = atoi( optarg );
  1691. X      break;
  1692. X
  1693. Xcase 'b':
  1694. X      bflg++;
  1695. X      bottom = atoi( optarg );
  1696. X      break;
  1697. X
  1698. Xcase '?':
  1699. Xdefault:
  1700. X       errflg++;
  1701. X    }
  1702. X    if (errflg)
  1703. X    { fprintf( stderr, "%s: ERROR. incorrect flag\n", Program );
  1704. X      fprintf( stderr, usage, Program );
  1705. X      exit(1);
  1706. X  } }
  1707. X
  1708. X  if ( argc - optind > 1 )
  1709. X  { fprintf( stderr, "%s: ERROR. more than 1 inputfile given.\n", Program );
  1710. X    fprintf( stderr, usage, Program );
  1711. X    exit( 2 );
  1712. X  }
  1713. X
  1714. X  if ( optind == argc - 1 )
  1715. X  { ifd = fopen( argv[optind], "r" );
  1716. X    if ( ifd == NULL )
  1717. X    { fprintf( stderr, "%s: can't open.\n", argv[optind] );
  1718. X      exit( 3 );
  1719. X    }
  1720. X    strcpy( name, argv[optind] );
  1721. X  }
  1722. X  else
  1723. X  { ifd = stdin;
  1724. X    strcpy( name, "noname" );
  1725. X  }
  1726. X
  1727. X  bitsr = pbm_readpbm( ifd, &cols, &rows );
  1728. X
  1729. X  if ( ifd != stdin )
  1730. X    fclose( ifd );
  1731. X    
  1732. X  bits = pbm_allocarray( MAX_COLS, MAX_LINES );
  1733. X
  1734. X  if( !lflg )
  1735. X    left = 0;
  1736. X
  1737. X  if( rflg )
  1738. X  { if( right - left >= MAX_COLS )
  1739. X      right = left + MAX_COLS - 1;
  1740. X  }
  1741. X  else
  1742. X    right = ( left + MAX_COLS > cols ) ? ( cols - 1 ) : ( left + MAX_COLS - 1 );
  1743. X
  1744. X  if( !tflg )
  1745. X    top = 0;
  1746. X
  1747. X  if( bflg )
  1748. X  { if( bottom - top >= MAX_LINES )
  1749. X      bottom = top + MAX_LINES - 1;
  1750. X  }
  1751. X  else
  1752. X    bottom = ( top + MAX_LINES > rows ) ?
  1753. X           ( rows - 1 ) : ( top + MAX_LINES - 1 );
  1754. X  
  1755. X  if( !checkborders( top, left, bottom, right ) )
  1756. X    exit( 4 );
  1757. X
  1758. X  fillbits( bits, bitsr, top, left, bottom, right );
  1759. X
  1760. X  writemacp( bits );
  1761. X
  1762. X} /* main */
  1763. X
  1764. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1765. X
  1766. Xcheckborders( top, left, bottom, right )
  1767. Xint top, left, bottom, right;
  1768. X{ if( right <= left || left < 0 || right - left + 1 > MAX_COLS )
  1769. X  { fprintf(stderr,"%s: error in right (= %d) and/or left (=%d)\n",
  1770. X          Program,right,left );
  1771. X    return( FALSE );
  1772. X  }
  1773. X  if( bottom <= top || top < 0 || bottom - top + 1 > MAX_LINES )
  1774. X  { fprintf(stderr,"%s: error in bottom (= %d) and/or top (=%d)\n",
  1775. X          Program,bottom,top );
  1776. X    return( FALSE );
  1777. X  }
  1778. X  return( TRUE );
  1779. X} /* checkborders */
  1780. X
  1781. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1782. X
  1783. X/* centreer het over te zenden plaatje in het MacPaint document
  1784. X *
  1785. X * Het plaatje wordt vanaf al of niet opgegeven (left, bottom)
  1786. X * in een pbm bitmap van de juist macpaint afmetingen gezet,
  1787. X * en eventueel afgekapt.
  1788. X */
  1789. Xfillbits( bits, bitsr, top, left, bottom, right )
  1790. Xbit **bits, **bitsr;
  1791. Xint top, left, bottom, right;
  1792. X{ register bit *bi, *bir;
  1793. X  register int i, j;
  1794. X  register int bottomr, leftr, topr, rightr;
  1795. X  int width, height;
  1796. X
  1797. X  width = right - left + 1;
  1798. X  leftr = (MAX_COLS - width) / 2;
  1799. X  rightr = leftr + width - 1;
  1800. X
  1801. X  height = bottom - top + 1;
  1802. X  topr = ( MAX_LINES - height ) / 2;
  1803. X  bottomr = topr + height - 1;
  1804. X
  1805. X  for( i = 0; i < topr; i++ )
  1806. X  { bi = bits[i];
  1807. X    for( j = 0; j < MAX_COLS; j++ )
  1808. X      *bi++ = 0;
  1809. X  }
  1810. X
  1811. X  for( i = topr; i <= bottomr; i++ )
  1812. X  { bi = bits[i];
  1813. X    { for( j = 0; j < leftr; j++ )
  1814. X    *bi++ = 0;
  1815. X      bir = bitsr[ i - topr + top ];
  1816. X      for( j = leftr; j <= rightr; j++ )
  1817. X    *bi++ = bir[j - leftr + left];
  1818. X      for( j = rightr + 1; j < MAX_COLS; j++ )
  1819. X    *bi++ = 0;
  1820. X  } }
  1821. X
  1822. X  for( i = bottomr + 1; i < MAX_LINES; i++ )
  1823. X  { bi = bits[i];
  1824. X    for( j = 0; j < MAX_COLS; j++ )
  1825. X      *bi++ = 0;
  1826. X  }
  1827. X} /* fillbits */
  1828. X      
  1829. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1830. X
  1831. Xwritemacp( bits )
  1832. Xbit **bits;
  1833. X{ register int i;
  1834. X  bit pb[MAX_COLS * 2];
  1835. X  int npb;
  1836. X
  1837. X  header();
  1838. X  for( i=0; i < MAX_LINES; i++ )
  1839. X  { npb = packit( pb, bits[i] );
  1840. X    sendbytes( pb, npb );
  1841. X  }
  1842. X} /* writemacp */
  1843. X
  1844. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1845. X
  1846. X/* pack regel van MacPaint doc in Apple's format
  1847. X * return value = # of bytes in pb 
  1848. X */
  1849. Xint
  1850. Xpackit( pb, bits )
  1851. Xbit *pb, *bits;
  1852. X{ register int i, charcount, npb, newcount, flg;
  1853. X  bit temp[72];
  1854. X  bit *count, *srcb, *destb, save;
  1855. X
  1856. X  srcb = bits; destb = temp;
  1857. X  filltemp( destb, srcb );
  1858. X  srcb = temp;
  1859. X  destb = pb;
  1860. X  npb = 0;
  1861. X  charcount = BYTES_WIDE;
  1862. X  flg = EQUAL;
  1863. X  while( charcount )
  1864. X  { save = *srcb++;
  1865. X    charcount--;
  1866. X    newcount = 1;
  1867. X    while( (*srcb == save) && charcount )
  1868. X    { srcb++;
  1869. X      newcount++;
  1870. X      charcount--;
  1871. X    }
  1872. X    if( newcount > 2 )
  1873. X    { count = destb++;
  1874. X      *count = 257 - newcount;
  1875. X      *destb++ = save;
  1876. X      npb += 2;
  1877. X      flg = EQUAL;
  1878. X    }
  1879. X    else
  1880. X    { if( flg == EQUAL )
  1881. X      { count = destb++;
  1882. X    *count = newcount - 1;
  1883. X    npb++;
  1884. X      }
  1885. X      else
  1886. X    *count += newcount;
  1887. X      while( newcount-- )
  1888. X      { *destb++ = save;
  1889. X        npb++;
  1890. X      }
  1891. X      flg = UNEQUAL;
  1892. X  } }
  1893. X  return npb;
  1894. X} /* packit */
  1895. X
  1896. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1897. X
  1898. Xfilltemp( dest, src )
  1899. Xbit *src, *dest;
  1900. X{ register unsigned char ch, zero, acht;
  1901. X  register int i, j;
  1902. X
  1903. X  zero = '\0';
  1904. X  acht = 8;
  1905. X  i = BYTES_WIDE;
  1906. X  while( i-- )
  1907. X  { ch = zero; 
  1908. X    j = acht;
  1909. X    while( j-- )
  1910. X    { ch <<= 1;
  1911. X      if( *src++ )
  1912. X    ch++;
  1913. X    }
  1914. X    *dest++ = ch;
  1915. X  }
  1916. X} /* filltemp */
  1917. X
  1918. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1919. X
  1920. Xsendbytes( pb, npb )
  1921. Xbit *pb;
  1922. Xregister int npb;
  1923. X{ register bit *b;
  1924. X
  1925. X  b = pb;
  1926. X  while( npb-- )
  1927. X    putc( *b++, fdout );
  1928. X} /* sendbytes */
  1929. X
  1930. X/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1931. X
  1932. Xheader()
  1933. X{ register int i;
  1934. X  register char ch;
  1935. X
  1936. X  /* header contains nothing ... */
  1937. X  ch = '\0';
  1938. X  for(i = 0; i < HEADER_LENGTH; i++ )
  1939. X    putc( ch, fdout );
  1940. X} /* header */
  1941. SHAR_EOF
  1942. if test 6598 -ne "`wc -c < 'pbmtomacp.c'`"
  1943. then
  1944.     echo shar: error transmitting "'pbmtomacp.c'" '(should have been 6598 characters)'
  1945. fi
  1946. fi # end of overwriting check
  1947. #    End of shell archive
  1948. exit 0
  1949.